package com.itheima.health.dao;

import com.itheima.health.pojo.entity.HotSetmeal;
import com.itheima.health.pojo.entity.Order;
import com.itheima.health.pojo.vo.SetmealCountSubVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 订单 DAO
 */
@Mapper
public interface OrderDao {
    /**
     * 查询全部套餐名称
     *
     * @return
     */
    List<String> selectSetmealNames();

    /**
     * 查询TOP5的套餐名称及套餐预约数量
     *
     * @return
     */
    List<SetmealCountSubVO> selectTop5Setmeals();


    /**
     * @Author liyichen
     * @Description 预约统计
     * @Date 9:19 2024/7/11
     * @param
     * @return java.util.Map<java.lang.String,java.lang.Long>
     */
    @Select("SELECT " +
            "(SELECT COUNT(*) FROM t_order WHERE orderDate = CURDATE()) AS todayOrderNumber," +
            "(SELECT COUNT(*) FROM t_order WHERE orderDate = CURDATE() AND orderStatus = '已到诊')AS todayVisitsNumber," +
            "(SELECT COUNT(*) FROM t_order WHERE YEARWEEK(orderDate, 1) = YEARWEEK(CURDATE(), 1))AS thisWeekOrderNumber," +
            "(SELECT COUNT(*) FROM t_order WHERE YEARWEEK(orderDate, 1) = YEARWEEK(CURDATE(), 1) AND orderStatus = '已到诊')AS thisWeekVisitsNumber," +
            "(SELECT COUNT(*) FROM t_order WHERE MONTH(orderDate) = MONTH(CURDATE()) AND YEAR(orderDate) = YEAR(CURDATE()))AS thisMonthOrderNumber," +
            "(SELECT COUNT(*) FROM t_order WHERE MONTH(orderDate) = MONTH(CURDATE()) AND YEAR(orderDate) = YEAR(CURDATE()) AND orderStatus = '已到诊')AS thisMonthVisitsNumber")
    @Results({
            @Result(property = "todayOrderNumber", column = "todayOrderNumber"),
            @Result(property = "todayVisitsNumber", column = "todayVisitsNumber"),
            @Result(property = "thisWeekOrderNumber", column = "thisWeekOrderNumber"),
            @Result(property = "thisWeekVisitsNumber", column = "thisWeekVisitsNumber"),
            @Result(property = "thisMonthOrderNumber", column = "thisMonthOrderNumber"),
            @Result(property = "thisMonthVisitsNumber", column = "thisMonthVisitsNumber")
    })
    Map<String, Long> getOrderReport();

    /**
     * @Author liyichen
     * @Description 热点套餐
     * @Date 9:19 2024/7/11
     * @param
     * @return java.util.List<com.itheima.health.pojo.entity.HotSetmeal>
     */
    List<HotSetmeal> selectTopSetmeals();

    List<Order> findByCondition(Order order);

    void add(Order order);

    /**
     * 根据id查询订单详细信息
     * @param id
     * @return
     */
    Map selectById(Integer id);
}
